package com.kuang.controller;

import com.kuang.common.anno.IgnoreToken;
import com.kuang.common.base.BaseController;
import com.kuang.generator.redis.IGeneratorIdService;
import com.kuang.generator.snow.SnowFlakeShortUrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GeneratorController extends BaseController {

    @Autowired
    private IGeneratorIdService generatorIdService;

    // http://localhost:8089/api/v1/generator/id
    @GetMapping("/generator/id")
    @IgnoreToken
    public Long generatorid(){
        SnowFlakeShortUrl snowFlake = new SnowFlakeShortUrl(2, 3);
        return snowFlake.nextId();
    }

    // http://localhost:8089/api/v1/redis/generator1
    @GetMapping("/redis/generator1")
    @IgnoreToken
    public Long redisgenerator1(){
        return generatorIdService.genUid("ksd:order:generator:id");
    }

    // http://localhost:8089/api/v1/redis/generator2
    @GetMapping("/redis/generator2")
    @IgnoreToken
    public String redisgenerator2(){
        return generatorIdService.getSequence("ksd:generator:id:");
    }
}
